package com.dz.goods.controller;

import com.dz.common.base.BaseApiService;
import com.dz.common.base.BasePageResultsVO;
import com.dz.common.base.ResponseBase;
import com.dz.goods.domain.entity.Template;
import com.dz.goods.domain.vo.TemplateParamsVO;
import com.dz.goods.domain.vo.TemplateResultsVO;
import com.dz.goods.service.TemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/goods/template")
@Api(tags = "模板管理")
public class TemplateController extends BaseApiService {

    @Autowired
    private TemplateService templateService;

    @GetMapping("/get_template_list")
    @ApiOperation(value = "条件查询模板")
    public ResponseBase getAlbumList(TemplateParamsVO vo) throws Exception {
        BasePageResultsVO<TemplateResultsVO> templateList = templateService.getTemplateList(vo);
        return setResultSuccess(templateList) ;
    }
    @PostMapping("/add")
    @ApiOperation(value = "添加模板")
    public ResponseBase add(@RequestBody Template template) throws Exception {
        Template add = templateService.add(template);
        return setResultSuccess(add) ;
    }
    @PostMapping("/edit")
    @ApiOperation(value = "更新模板")
    public ResponseBase edit(@RequestBody Template template) throws Exception {
        Template edit = templateService.edit(template);
        return setResultSuccess(edit) ;
    }
    @GetMapping("/get_by_id")
    @ApiOperation(value = "根据id查询模板")
    public ResponseBase getById(Long templateId) throws Exception {
        Template album = templateService.findById(templateId);
        return setResultSuccess(album) ;
    }

    @DeleteMapping("/delete")
    @ApiOperation(value = "删除模板")
    public ResponseBase delete(Long templateId) throws Exception {
        templateService.delete(templateId);
        return setResultSuccess();
    }
    @GetMapping("/get_by_category_id")
    @ApiOperation(value = "根据分类id查询模板")
    public ResponseBase findByCategoryId(Long id) throws Exception {
        TemplateResultsVO  templateResultsVO= templateService.findByCategoryId(id);
        return setResultSuccess(templateResultsVO) ;
    }
}